#!/bin/bash
root_dir="/usr/local/edh"
if [ ! -d "$root_dir" ];then
  echo "$(date +"%Y-%m-%d %H:%M:%S") WARNING $root_dir undetected"
  mkdir -p $root_dir
  if [ $? -eq 0 ];then
    echo "$(date +"%Y-%m-%d %H:%M:%S") INFO creating $root_dir success"
  else
    echo "$(date +"%Y-%m-%d %H:%M:%S") ERROR creating $root_dir fail"
    exit 1
  fi
else
  echo "$(date +"%Y-%m-%d %H:%M:%S") INFO $root_dir detected"
fi

if [ ! -d "$root_dir/python" ];then
  echo "$(date +"%Y-%m-%d %H:%M:%S") INFO $root_dir/python undetected"
  tar -zxvf Python-3.11.13.tgz
  apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev curl
  ./Python-3.11.13/configure --prefix=$root_dir/python --enable-optimizations
  make altinstall
  echo "export PYTHON_HOME=$root_dir/python" >> ~/.bashrc
  echo 'export PATH=$PYTHON_HOME/bin:$PATH' >> ~/.bashrc
  echo "export PYTHON_HOME=$root_dir/python" >> /etc/profile
  echo 'export PATH=$PYTHON_HOME/bin:$PATH' >> /etc/profile
  source ~/.bashrc
  source /etc/profile
  python --version
else
  source ~/.bashrc
  source /etc/profile
  python --version
fi




